import redis

# 创建 Redis 连接对象
r = redis.Redis(host='localhost', port=6379, db=0)

# 创建连接池
pool = redis.ConnectionPool(host='localhost', port=6379, db=0)

# 使用连接池创建 Redis 连接对象
r = redis.Redis(connection_pool=pool)

# 执行操作
r.set('key', 'value')
print(r.get('key').decode('utf-8'))